package com.bianmaba.spring.mvc.controller;

import com.bianmaba.spring.data.jpa.service.IBaseService;
import com.bianmaba.spring.mvc.method.support.annotations.EntityParam;
import com.bianmaba.spring.mvc.method.support.annotations.JSON;
import org.springframework.web.bind.annotation.RequestMapping;

import java.io.Serializable;

public abstract class CrudController<T, ID extends Serializable> extends ReadController<T, ID> {

    protected IBaseService<T, ID> getService() {
        return null;
    }

    @JSON()
    @RequestMapping(value = "/save")
    public T save(@EntityParam T entity) {
        T result = getService().save(entity);
        return result;
    }


    @JSON()
    @RequestMapping(value = "/deletes")
    public boolean deletes(ID[] ids) {
        getService().delete(ids);
        return true;
    }

    @JSON()
    @RequestMapping(value = "/delete")
    public boolean delete(ID id) {
        getService().delete(id);
        return true;
    }
}
